using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Network;
using MicroMsg.Resource.@string;
using MicroMsg.Scene;
using MicroMsg.Scene.Image;
using MicroMsg.Storage;
using MicroMsg.UI.UserContrl;
using MicroMsg.UI.Util;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using Microsoft.Xna.Framework.Media;
using System;
using System.Diagnostics;
using System.IO;
using System.IO.IsolatedStorage;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
namespace MicroMsg.UI.Page
{
	public class ImageView : BasePage
	{
		private const double screenW = 480.0;
		private const double screenH = 750.0;
		private ChatMsg mCuMsg;
		private string mCuImgStr;
		private int imageLen;
		private MassMsg mCuMassMsg;
		private EventWatcher downLoadSuccessWatcher;
		private EventWatcher downLoadFailWatcher;
		private EventWatcher downLoadProgressWatcher;
		private ApplicationBar mBar;
		private ApplicationBarIconButton SaveMenuBtn;
		private bool isEnableDrag = true;
		private double initialAngle;
		private double initialScale;
		private double initialX;
		private double initialY;
		private double maxRadio = 5.0;
		internal Canvas LayoutRoot;
		internal Border ImgView;
		internal Image ShowImg;
		internal CompositeTransform transform;
		internal GestureListener borderListener;
		internal Canvas LoadingView;
		internal Image DefaultImg;
		internal DownloadProgressBar DownLoadProgressBar;
		internal TextBlock InfoTxt;
		private bool _contentLoaded;
		public ImageView()
		{
			this.InitializeComponent();
			base.add_Loaded(new RoutedEventHandler(this.ImageView_Loaded));
			base.add_Unloaded(new RoutedEventHandler(this.ImageView_Unloaded));
		}
		protected override void OnPageIn(object[] object_0)
		{
			if (this.mCuMsg != null && this.mCuMassMsg == null)
			{
				return;
			}
			if (object_0 == null)
			{
				return;
			}
			if (object_0.Length < 1)
			{
				return;
			}
			base.set_ApplicationBar(this.GetAppBar());
			if (object_0[0] is MassMsg)
			{
				this.mCuMassMsg = (object_0[0] as MassMsg);
				this.ShowImgView(this.mCuMassMsg.strFileName);
				return;
			}
			this.mCuMsg = (object_0[0] as ChatMsg);
			if (this.mCuMsg == null)
			{
				return;
			}
			this.ImgDownLoadInit();
			string msgImage = ChatMsgMgr.getMsgImage(this.mCuMsg);
			BitmapImage bitmapImage = ImageCacheMgr.loadImage(ChatMsgMgr.getMsgThumbnail(this.mCuMsg), ImageCacheType.MsgImg);
			if (string.IsNullOrEmpty(msgImage))
			{
				Log.smethod_5(base.GetType().get_Name(), "mCuMsg.nStatus = " + this.mCuMsg.nStatus);
				Log.smethod_5(base.GetType().get_Name(), "start download,local id:" + this.mCuMsg.nMsgLocalID);
				if (this.mCuMsg.IsAppMsg())
				{
					this.imageLen = this.getAppMsgAttachSize(object_0);
					bool flag;
					if (!(flag = ServiceCenter.sceneDownloadAppAttach.doScene(this.mCuMsg)) && bitmapImage != null)
					{
						this.ShowImg.set_Source(bitmapImage);
						this.LoadingView.set_Visibility(1);
						this.ImgView.set_Visibility(0);
						return;
					}
					if (!flag && bitmapImage == null)
					{
						this.ShowFailView();
						return;
					}
				}
				else
				{
					if (ChatMsgMgr.downloadMsgImage(this.mCuMsg, 0) == 0)
					{
						Log.smethod_1(base.GetType().get_Name(), "not app msg, error maybe, hah");
						this.ShowFailView();
						return;
					}
				}
			}
			else
			{
				Log.smethod_5(base.GetType().get_Name(), "image already download:" + msgImage);
				this.ShowImgView(msgImage);
			}
		}
		private void ImageView_Unloaded(object sender, RoutedEventArgs e)
		{
			this.ImgDownLoadUnit();
			ServiceCenter.sceneDownloadAppAttach.cancel();
		}
		private void ImageView_Loaded(object sender, RoutedEventArgs e)
		{
		}
		public void ShowFailView()
		{
			this.SaveMenuBtn.set_IsEnabled(true);
			this.isEnableDrag = false;
			this.LoadingView.set_Visibility(0);
			this.ImgView.set_Visibility(1);
			this.InfoTxt.set_Text(strings.ImageViewDownError);
		}
		public void ShowImgView(string imgUrl)
		{
			this.LayoutRoot.set_Background(new SolidColorBrush(Colors.get_Black()));
			this.SaveMenuBtn.set_IsEnabled(true);
			if (string.IsNullOrEmpty(imgUrl))
			{
				this.ShowFailView();
				return;
			}
			this.mCuImgStr = imgUrl;
			BitmapImage bitmapImage = ImageCacheMgr.loadFromFile(imgUrl);
			if (bitmapImage == null)
			{
				this.InfoTxt.set_Text(strings.ImageViewLoadError);
				this.LoadingView.set_Visibility(0);
				this.ImgView.set_Visibility(1);
				return;
			}
			this.ShowImg.set_Source(bitmapImage);
			this.LoadingView.set_Visibility(1);
			this.ImgView.set_Visibility(0);
			if (bitmapImage != null)
			{
				double num = Math.Max(480.0 / (double)bitmapImage.get_PixelWidth(), (double)bitmapImage.get_PixelWidth() / 480.0);
				double num2 = Math.Max(800.0 / (double)bitmapImage.get_PixelHeight(), (double)bitmapImage.get_PixelHeight() / 800.0);
				this.maxRadio = Math.Max(Math.Max(num, num2), 5.0);
				return;
			}
			this.maxRadio = 5.0;
		}
		private int getAppMsgAttachSize(object[] object_0)
		{
			if (this.mCuMsg == null || !this.mCuMsg.IsAppMsg())
			{
				return 0;
			}
			AppMsgInfo appMsgInfo = AppMsgMgr.parseAppXml(this.mCuMsg.strMsg);
			if (appMsgInfo != null && !string.IsNullOrEmpty(appMsgInfo.attachid) && appMsgInfo.totallength > 0)
			{
				return appMsgInfo.totallength / 1000;
			}
			return 0;
		}
		private void ImgDownLoadInit()
		{
			this.downLoadSuccessWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadSuccess_EventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE, this.downLoadSuccessWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_COMPLETE, this.downLoadSuccessWatcher);
			this.downLoadFailWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadFail_EventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_FAIL, this.downLoadFailWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_FAIL, this.downLoadFailWatcher);
			this.downLoadProgressWatcher = new EventWatcher(this, null, new EventHandlerDelegate(this.on_LoadProgress_EventHandler));
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS, this.downLoadProgressWatcher);
			EventCenter.registerEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_PROGRESS, this.downLoadProgressWatcher);
		}
		private void ImgDownLoadUnit()
		{
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE, this.downLoadSuccessWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_FAIL, this.downLoadFailWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS, this.downLoadProgressWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_COMPLETE, this.downLoadSuccessWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_FAIL, this.downLoadFailWatcher);
			EventCenter.removeEventWatcher(EventConst.ON_NETSCENE_DOWNLOAD_ATTACH_PROGRESS, this.downLoadProgressWatcher);
		}
		private void on_LoadProgress_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			if (!NetworkDeviceWatcher.isCurrentWifi())
			{
				return;
			}
			Log.smethod_4(base.GetType().get_Name(), "on_LoadProgress_EventHandler");
			if (evtArgs == null)
			{
				return;
			}
			double num;
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_DOWNLOADIMG_PROGRESS)
			{
				ParamImgDownProgress paramImgDownProgress = evtArgs.mObject as ParamImgDownProgress;
				num = double.Parse(paramImgDownProgress.mstrProgress);
			}
			else
			{
				ParamDownloadAppAttach paramDownloadAppAttach = evtArgs.mObject as ParamDownloadAppAttach;
				num = double.Parse(paramDownloadAppAttach.mstrProgress);
			}
			if (this.imageLen <= 0)
			{
				return;
			}
			int num2 = (int)num;
			if (num2 >= this.imageLen - 3)
			{
				num2 = this.imageLen - 3;
			}
			double num3 = (double)num2 / (double)this.imageLen * 100.0;
			if (num3 > this.DownLoadProgressBar.get_Value())
			{
				this.DownLoadProgressBar.set_Value(num3);
			}
			this.InfoTxt.set_Text(string.Format(strings.ImageViewDownInfo, num2, this.imageLen));
		}
		private void on_LoadSuccess_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5(base.GetType().get_Name(), "on_LoadSuccess_EventHandler");
			if (evtArgs == null)
			{
				this.ShowFailView();
				return;
			}
			if (evtArgs.mObject == null)
			{
				this.ShowFailView();
				return;
			}
			string text;
			if (evtArgs.mEventID == EventConst.ON_NETSCENE_DOWNLOADIMG_COMPLETE)
			{
				ParamReturn paramReturn = evtArgs.mObject as ParamReturn;
				if (paramReturn == null)
				{
					this.ShowFailView();
					return;
				}
				text = paramReturn.mStrImgPath;
			}
			else
			{
				ParamDownloadAppAttach paramDownloadAppAttach = evtArgs.mObject as ParamDownloadAppAttach;
				if (paramDownloadAppAttach == null)
				{
					this.ShowFailView();
					return;
				}
				text = paramDownloadAppAttach.mImagePath;
			}
			if (string.IsNullOrEmpty(text))
			{
				this.ShowFailView();
				return;
			}
			this.ShowImgView(text);
		}
		private void on_LoadFail_EventHandler(EventWatcher watcher, BaseEventArgs evtArgs)
		{
			Log.smethod_5(base.GetType().get_Name(), "on_LoadFail_EventHandler");
			this.ShowFailView();
		}
		private void SavaPic()
		{
			if (string.IsNullOrEmpty(this.mCuImgStr))
			{
				return;
			}
			if (this.ShowImg.get_Source() == null)
			{
				return;
			}
			try
			{
				using (IsolatedStorageFile userStoreForApplication = IsolatedStorageFile.GetUserStoreForApplication())
				{
					using (IsolatedStorageFileStream isolatedStorageFileStream = userStoreForApplication.OpenFile(this.mCuImgStr, 3, 1))
					{
						MediaLibrary mediaLibrary = new MediaLibrary();
						if (this.mCuMsg.IsAppMsg())
						{
							MemoryStream memoryStream = new MemoryStream();
							bool flag = Util.saveThumb(isolatedStorageFileStream, memoryStream, 960, 960, 100);
							memoryStream.Seek(0L, 0);
							if (flag)
							{
								mediaLibrary.SavePicture(this.GetExisPicName(), memoryStream);
							}
						}
						else
						{
							mediaLibrary.SavePicture(this.GetExisPicName(), isolatedStorageFileStream);
						}
						isolatedStorageFileStream.Close();
					}
				}
				MessageBoxManager.ShowToast(strings.ImageViewSaveSuccess, 2500, null, false);
			}
			catch (Exception ex)
			{
				Log.smethod_1(base.GetType().get_Name(), "SavaPic Exception" + ex.get_StackTrace());
				MMMessageBox.Show(strings.ImageViewSaveFail, true, "确定");
			}
		}
		private string GetExisPicName()
		{
			return "MicroMsg" + DateTime.get_Now().get_Ticks() + ".jpg";
		}
		private ApplicationBar GetAppBar()
		{
			this.mBar = new ApplicationBar();
			this.mBar.set_IsVisible(true);
			if (this.mBar != null)
			{
				this.mBar.set_BackgroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_BK_BRUSH).get_Color());
				this.mBar.set_ForegroundColor(((SolidColorBrush)R.theme.COMMON_APPBAR_FG_BRUSH).get_Color());
			}
			this.SaveMenuBtn = new ApplicationBarIconButton(new Uri("/Resource/Img/Chat/Save.png", 2));
			this.SaveMenuBtn.set_Text(strings.ImageViewSave);
			this.SaveMenuBtn.add_Click(new EventHandler(this.SavaMenuBtn_Click));
			this.mBar.get_Buttons().Add(this.SaveMenuBtn);
			this.SaveMenuBtn.set_IsEnabled(false);
			this.setAppBarStyle(this.mBar);
			return this.mBar;
		}
		private void SavaMenuBtn_Click(object sender, EventArgs e)
		{
			this.SavaPic();
		}
		private void OnPinchStarted(object sender, PinchStartedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.initialScale = this.transform.get_ScaleX();
		}
		private CompositeTransform GetCopyTransform(CompositeTransform trans)
		{
			CompositeTransform compositeTransform = new CompositeTransform();
			compositeTransform.set_CenterX(trans.get_CenterX());
			compositeTransform.set_CenterY(trans.get_CenterY());
			compositeTransform.set_ScaleX(trans.get_ScaleX());
			compositeTransform.set_ScaleY(trans.get_ScaleY());
			compositeTransform.set_TranslateX(trans.get_TranslateX());
			compositeTransform.set_TranslateY(trans.get_TranslateY());
			return compositeTransform;
		}
		private CompositeTransform GetContraryTransform(CompositeTransform trans)
		{
			CompositeTransform compositeTransform = new CompositeTransform();
			compositeTransform.set_CenterX(0.0);
			compositeTransform.set_CenterY(0.0);
			compositeTransform.set_ScaleX(1.0 / trans.get_ScaleX());
			compositeTransform.set_ScaleY(1.0 / trans.get_ScaleY());
			compositeTransform.set_TranslateX(0.0 - trans.get_TranslateX());
			compositeTransform.set_TranslateY(0.0 - trans.get_TranslateY());
			return compositeTransform;
		}
		private void OnPinchDelta(object sender, PinchGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			double num = e.DistanceRatio;
			if (num > 2.0)
			{
				num = 2.0;
			}
			else
			{
				if (num < 0.3)
				{
					num = 0.3;
				}
			}
			if (this.initialScale * num > 0.65 && this.initialScale * num < this.maxRadio)
			{
				Point resultPoint = new Point(e.GetPosition(this.ImgView).get_X(), e.GetPosition(this.ImgView).get_Y());
				Point pointSrc = default(Point);
				bool oldPoint = this.GetOldPoint(resultPoint, this.transform, ref pointSrc);
				CompositeTransform copyTransform = this.GetCopyTransform(this.transform);
				copyTransform.set_ScaleX(this.initialScale * num);
				copyTransform.set_ScaleY(this.initialScale * num);
				Point point = default(Point);
				bool oldPoint2 = this.GetOldPoint(resultPoint, copyTransform, ref point);
				Point point2 = default(Point);
				bool transformPoint = this.GetTransformPoint(pointSrc, copyTransform, ref point2);
				this.transform.set_ScaleX(this.initialScale * num);
				this.transform.set_ScaleY(this.initialScale * num);
				if (oldPoint && oldPoint2 && transformPoint)
				{
					CompositeTransform expr_148 = this.transform;
					expr_148.set_TranslateX(expr_148.get_TranslateX() + (resultPoint.get_X() - point2.get_X()));
					CompositeTransform expr_169 = this.transform;
					expr_169.set_TranslateY(expr_169.get_TranslateY() + (resultPoint.get_Y() - point2.get_Y()));
				}
				return;
			}
		}
		private void GestureListener_DragStarted(object sender, DragStartedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.initialX = this.transform.get_TranslateX();
			this.initialY = this.transform.get_TranslateY();
		}
		private void GestureListener_DragDelta(object sender, DragDeltaGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			CompositeTransform expr_0F = this.transform;
			expr_0F.set_TranslateX(expr_0F.get_TranslateX() + e.HorizontalChange * 1.2);
			CompositeTransform expr_31 = this.transform;
			expr_31.set_TranslateY(expr_31.get_TranslateY() + e.VerticalChange * 1.2);
		}
		private void GestureListener_DragCompleted(object sender, DragCompletedGestureEventArgs e)
		{
			if (!this.isEnableDrag)
			{
				return;
			}
			this.AdjustImagePosition();
		}
		private void AdjustImagePosition()
		{
			double num = 0.0;
			double num2 = 0.0;
			if (!this.IsShouldReplace(ref num, ref num2))
			{
				return;
			}
			TimeSpan timeSpan = TimeSpan.FromSeconds(0.3);
			Storyboard storyboard = new Storyboard();
			double num3 = this.transform.get_TranslateX();
			double num4 = this.transform.get_TranslateX() + num;
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(num3));
			doubleAnimation.set_To(new double?(num4));
			doubleAnimation.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation2 = doubleAnimation;
			Storyboard.SetTarget(doubleAnimation2, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(CompositeTransform.TranslateXProperty));
			storyboard.get_Children().Add(doubleAnimation2);
			num3 = this.transform.get_TranslateY();
			num4 = this.transform.get_TranslateY() + num2;
			DoubleAnimation doubleAnimation3 = new DoubleAnimation();
			doubleAnimation3.set_From(new double?(num3));
			doubleAnimation3.set_To(new double?(num4));
			doubleAnimation3.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation4 = doubleAnimation3;
			Storyboard.SetTarget(doubleAnimation4, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath(CompositeTransform.TranslateYProperty));
			storyboard.get_Children().Add(doubleAnimation4);
			storyboard.Begin();
		}
		private void ResumeStoryBoard()
		{
			TimeSpan timeSpan = TimeSpan.FromSeconds(0.3);
			Storyboard storyboard = new Storyboard();
			double num = this.transform.get_ScaleX();
			double num2 = 1.0;
			DoubleAnimation doubleAnimation = new DoubleAnimation();
			doubleAnimation.set_From(new double?(num));
			doubleAnimation.set_To(new double?(num2));
			doubleAnimation.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation2 = doubleAnimation;
			Storyboard.SetTarget(doubleAnimation2, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(CompositeTransform.ScaleXProperty));
			storyboard.get_Children().Add(doubleAnimation2);
			num = this.transform.get_ScaleY();
			num2 = 1.0;
			DoubleAnimation doubleAnimation3 = new DoubleAnimation();
			doubleAnimation3.set_From(new double?(num));
			doubleAnimation3.set_To(new double?(num2));
			doubleAnimation3.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation4 = doubleAnimation3;
			Storyboard.SetTarget(doubleAnimation4, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation4, new PropertyPath(CompositeTransform.ScaleYProperty));
			storyboard.get_Children().Add(doubleAnimation4);
			num = this.transform.get_TranslateX();
			num2 = 0.0;
			DoubleAnimation doubleAnimation5 = new DoubleAnimation();
			doubleAnimation5.set_From(new double?(num));
			doubleAnimation5.set_To(new double?(num2));
			doubleAnimation5.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation6 = doubleAnimation5;
			Storyboard.SetTarget(doubleAnimation6, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation6, new PropertyPath(CompositeTransform.TranslateXProperty));
			storyboard.get_Children().Add(doubleAnimation6);
			num = this.transform.get_TranslateY();
			num2 = 0.0;
			DoubleAnimation doubleAnimation7 = new DoubleAnimation();
			doubleAnimation7.set_From(new double?(num));
			doubleAnimation7.set_To(new double?(num2));
			doubleAnimation7.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation8 = doubleAnimation7;
			Storyboard.SetTarget(doubleAnimation8, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation8, new PropertyPath(CompositeTransform.TranslateYProperty));
			storyboard.get_Children().Add(doubleAnimation8);
			num = this.transform.get_CenterX();
			num2 = 0.0;
			DoubleAnimation doubleAnimation9 = new DoubleAnimation();
			doubleAnimation9.set_From(new double?(num));
			doubleAnimation9.set_To(new double?(num2));
			doubleAnimation9.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation10 = doubleAnimation9;
			Storyboard.SetTarget(doubleAnimation10, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation10, new PropertyPath(CompositeTransform.CenterXProperty));
			storyboard.get_Children().Add(doubleAnimation10);
			num = this.transform.get_CenterY();
			num2 = 0.0;
			DoubleAnimation doubleAnimation11 = new DoubleAnimation();
			doubleAnimation11.set_From(new double?(num));
			doubleAnimation11.set_To(new double?(num2));
			doubleAnimation11.set_Duration(timeSpan);
			DoubleAnimation doubleAnimation12 = doubleAnimation11;
			Storyboard.SetTarget(doubleAnimation12, this.transform);
			Storyboard.SetTargetProperty(doubleAnimation12, new PropertyPath(CompositeTransform.CenterYProperty));
			storyboard.get_Children().Add(doubleAnimation12);
			storyboard.Begin();
		}
		private Rect GetOriginRect(ref double xRadio, ref double yRadio)
		{
			Rect result = default(Rect);
			BitmapImage bitmapImage = this.ShowImg.get_Source() as BitmapImage;
			if (bitmapImage == null)
			{
				return result;
			}
			double num;
			double num2;
			double num5;
			double num6;
			if ((double)(bitmapImage.get_PixelHeight() / bitmapImage.get_PixelWidth()) > 1.5625)
			{
				num = 0.0;
				num2 = 750.0;
				double num3 = 750.0 / (double)bitmapImage.get_PixelHeight();
				double num4 = (double)bitmapImage.get_PixelWidth() * num3;
				num5 = (480.0 - num4) / 2.0;
				num6 = num5 + num4;
			}
			else
			{
				num5 = 0.0;
				num6 = 480.0;
				double num7 = 480.0 / (double)bitmapImage.get_PixelWidth();
				double num8 = (double)bitmapImage.get_PixelHeight() * num7;
				num = (750.0 - num8) / 2.0;
				num2 = 750.0 - num;
			}
			xRadio = (num6 - num5) / 480.0;
			yRadio = (num2 - num) / 750.0;
			result = new Rect(num5, num, num6 - num5, num2 - num);
			return result;
		}
		private bool IsShouldReplace(ref double detaX, ref double detaY)
		{
			Rect transformRect = this.GetTransformRect(this.transform);
			double num = 0.0;
			double num2 = 0.0;
			this.GetOriginRect(ref num, ref num2);
			if (transformRect.get_IsEmpty())
			{
				return false;
			}
			double num3;
			double num4;
			if (transformRect.get_Width() < 480.0)
			{
				num3 = (480.0 - transformRect.get_Width()) / 2.0;
				num4 = num3 + transformRect.get_Width();
			}
			else
			{
				num3 = 0.0;
				num4 = 480.0;
			}
			bool result = false;
			if (transformRect.get_Width() < 480.0)
			{
				if (transformRect.get_Left() < num3)
				{
					detaX = num3 - transformRect.get_Left();
					result = true;
				}
				else
				{
					if (transformRect.get_Right() > num4)
					{
						detaX = num4 - transformRect.get_Right();
						result = true;
					}
				}
			}
			else
			{
				if (transformRect.get_Left() > 0.0 && transformRect.get_Right() > 480.0)
				{
					detaX = 0.0 - transformRect.get_Left();
					if (detaX < 0.0)
					{
						result = true;
					}
					else
					{
						detaX = 0.0;
					}
				}
				else
				{
					if (transformRect.get_Left() < 0.0 && transformRect.get_Right() < 480.0)
					{
						detaX = 480.0 - transformRect.get_Right();
						if (detaX > 0.0)
						{
							result = true;
						}
						else
						{
							detaX = 0.0;
						}
					}
				}
			}
			double num5;
			double num6;
			if (transformRect.get_Height() < 750.0)
			{
				num5 = (750.0 - transformRect.get_Height()) / 2.0;
				num6 = num5 + transformRect.get_Height();
			}
			else
			{
				num5 = 0.0;
				num6 = 750.0;
			}
			if (transformRect.get_Height() < 750.0)
			{
				if (transformRect.get_Top() > num5)
				{
					detaY = num5 - transformRect.get_Top();
					result = true;
				}
				else
				{
					if (transformRect.get_Bottom() < num6)
					{
						detaY = num6 - transformRect.get_Bottom();
						result = true;
					}
				}
			}
			else
			{
				if (transformRect.get_Top() > 0.0 && transformRect.get_Bottom() > 750.0)
				{
					detaY = num5 - transformRect.get_Top();
					if (detaY < 0.0)
					{
						result = true;
					}
					else
					{
						detaY = 0.0;
					}
				}
				else
				{
					if (transformRect.get_Top() < 0.0 && transformRect.get_Bottom() < 750.0)
					{
						detaY = num6 - transformRect.get_Bottom();
						if (detaY >= 0.0)
						{
							result = true;
						}
						else
						{
							detaY = 0.0;
						}
					}
				}
			}
			return result;
		}
		private bool GetTransformPoint(Point pointSrc, CompositeTransform trans, ref Point resultPoint)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return false;
			}
			if (pointSrc.get_X() < originRect.get_Left() || pointSrc.get_X() > originRect.get_Right())
			{
				return false;
			}
			if (pointSrc.get_Y() >= originRect.get_Top() && pointSrc.get_Y() <= originRect.get_Bottom())
			{
				double num3 = (pointSrc.get_X() - originRect.get_Left()) / originRect.get_Width();
				double num4 = (pointSrc.get_Y() - originRect.get_Top()) / originRect.get_Height();
				Rect transformRect = this.GetTransformRect(trans);
				resultPoint = new Point(transformRect.get_Left() + transformRect.get_Width() * num3, transformRect.get_Top() + transformRect.get_Height() * num4);
				return true;
			}
			return false;
		}
		private bool GetOldPoint(Point resultPoint, CompositeTransform trans, ref Point pointSrc)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return false;
			}
			Rect transformRect = this.GetTransformRect(trans);
			if (resultPoint.get_X() < transformRect.get_Left() || resultPoint.get_X() > transformRect.get_Right())
			{
				return false;
			}
			if (resultPoint.get_Y() >= transformRect.get_Top() && resultPoint.get_Y() <= transformRect.get_Bottom())
			{
				double num3 = (resultPoint.get_X() - transformRect.get_Left()) / transformRect.get_Width();
				double num4 = (resultPoint.get_Y() - transformRect.get_Top()) / transformRect.get_Height();
				pointSrc = new Point(originRect.get_Left() + originRect.get_Width() * num3, originRect.get_Top() + originRect.get_Height() * num4);
				return true;
			}
			return false;
		}
		private Rect GetTransformRect(CompositeTransform trans)
		{
			double num = 0.0;
			double num2 = 0.0;
			Rect originRect = this.GetOriginRect(ref num, ref num2);
			if (originRect.get_IsEmpty())
			{
				return originRect;
			}
			Rect rect = new Rect(0.0, 0.0, originRect.get_Width(), originRect.get_Height());
			Rect rect2 = trans.TransformBounds(rect);
			Rect result = new Rect(originRect.get_Left() + rect2.get_Left(), originRect.get_Top() + rect2.get_Top(), rect2.get_Width(), rect2.get_Height());
			return result;
		}
		private void GestureListener_PinchCompleted(object sender, PinchGestureEventArgs e)
		{
			if (this.transform.get_ScaleX() < 1.0)
			{
				this.ResumeStoryBoard();
				return;
			}
			this.AdjustImagePosition();
		}
		[DebuggerNonUserCode]
		public void InitializeComponent()
		{
			if (this._contentLoaded)
			{
				return;
			}
			this._contentLoaded = true;
			Application.LoadComponent(this, new Uri("/MicroMsg;component/Source/UI/Chat/ImageView.xaml", 2));
			this.LayoutRoot = (Canvas)base.FindName("LayoutRoot");
			this.ImgView = (Border)base.FindName("ImgView");
			this.ShowImg = (Image)base.FindName("ShowImg");
			this.transform = (CompositeTransform)base.FindName("transform");
			this.borderListener = (GestureListener)base.FindName("borderListener");
			this.LoadingView = (Canvas)base.FindName("LoadingView");
			this.DefaultImg = (Image)base.FindName("DefaultImg");
			this.DownLoadProgressBar = (DownloadProgressBar)base.FindName("DownLoadProgressBar");
			this.InfoTxt = (TextBlock)base.FindName("InfoTxt");
		}
	}
}
